home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / src / srgp_output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  24.2 KB  |  1,067 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4.  
  5. #define TURN_OFF_RUBBER_ECHO_IF_ANY \
  6.    SRGP__disableLocatorRubberEcho()
  7.  
  8. #define TURN_ON_RUBBER_ECHO_IF_ANY \
  9.    SRGP__enableLocatorRubberEcho()
  10.  
  11.  
  12.  
  13.  
  14. #ifdef THINK_C
  15. static Rect r;
  16.  
  17. #define DONT_DRAW  -1   /* must match srgp_attrib.c */
  18.  
  19.  
  20. #define SET_PORT_FOR_FRAME_GENRE() \
  21. if (srgp__curActiveCanvasSpec.transfermode_frame == DONT_DRAW) return; else { \
  22.    PenMode (srgp__curActiveCanvasSpec.transfermode_frame); \
  23.    PenPat (srgp__curActiveCanvasSpec.pat_frame); }
  24.  
  25. #define SET_PORT_FOR_FILL_GENRE() \
  26. if (srgp__curActiveCanvasSpec.transfermode_fill == DONT_DRAW) return; else { \
  27.    PenMode (srgp__curActiveCanvasSpec.transfermode_fill); \
  28.    PenPat (srgp__curActiveCanvasSpec.pat_fill); }
  29.  
  30. #endif
  31.  
  32.  
  33.  
  34. /** Functions creating geometric data 
  35. **/
  36.  
  37. point SRGP_defPoint (int x, int y)
  38. {
  39.    point pt;
  40.  
  41.    pt.x = x;
  42.    pt.y = y;
  43.    return pt;
  44. }
  45.  
  46. rectangle SRGP_defRectangle (int left_x, int bottom_y, int right_x, int top_y)
  47. {
  48.    rectangle rect;
  49.  
  50.    rect.bottom_left.x = left_x;
  51.    rect.bottom_left.y = bottom_y;
  52.    rect.top_right.x = right_x;
  53.    rect.top_right.y = top_y;
  54.    return rect;
  55. }
  56.  
  57.  
  58.  
  59.  
  60. /** AUDIO
  61. **/
  62.  
  63. void
  64. SRGP_beep()
  65. {
  66. #ifdef X11
  67.    XBell (srgpx__display, 0);
  68. #endif
  69. #ifdef THINK_C
  70.    SysBeep(30);
  71. #endif
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /** POINTS 
  79. **/
  80.  
  81. void
  82. SRGP_pointCoord (int x, int y)
  83. {
  84.    DEBUG_AIDS{
  85.       SRGP_trace (SRGP_logStream, "SRGP_pointCoord: %d,%d\n", x,y);
  86.       srgp_check_system_state();
  87.       LeaveIfNonFatalErr();
  88.    }
  89.  
  90.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  91. #ifdef X11
  92.    XDrawPoint
  93.       (srgpx__display,
  94.        srgp__curActiveCanvasSpec.drawable.xid,
  95.        srgp__curActiveCanvasSpec.gc_frame,
  96.        x, FIXED(y));
  97. #endif
  98. #ifdef THINK_C
  99.    SET_PORT_FOR_FRAME_GENRE();
  100.    MoveTo(x,FIXED(y));
  101.    Line(0,0);
  102. #endif
  103.    TURN_ON_RUBBER_ECHO_IF_ANY;
  104. }
  105.  
  106. void
  107. SRGP_point (point pt)
  108. {
  109.    DEBUG_AIDS{
  110.       SRGP_trace (SRGP_logStream, "SRGP_point: %d,%d\n", ExplodePt(pt));
  111.    }
  112.  
  113.    PUSH_TRACE;
  114.    SRGP_pointCoord (pt.x, pt.y);
  115.    POP_TRACE;
  116. }
  117.  
  118. void
  119. SRGP_polyPoint (int vertex_count, point *vertices)
  120. {
  121.    register int i;
  122.  
  123.    DEBUG_AIDS{
  124.       SRGP_trace (SRGP_logStream, "SRGP_polyPoint  %d 0x%x\n", 
  125.            vertex_count, vertices);
  126.       srgp_check_system_state();
  127.       srgp_check_polymarker_list_size(vertex_count);
  128.       LeaveIfNonFatalErr();
  129.    }
  130.  
  131.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  132.  
  133. #ifdef X11
  134.    for (i=0; i<vertex_count; i++) {
  135.       Xformat_vertices[i].x = vertices[i].x;
  136.       Xformat_vertices[i].y = FIXED(vertices[i].y);
  137.    } 
  138.    XDrawPoints
  139.       (srgpx__display,
  140.        srgp__curActiveCanvasSpec.drawable.xid,
  141.        srgp__curActiveCanvasSpec.gc_frame,
  142.        Xformat_vertices, vertex_count, CoordModeOrigin);
  143. #endif
  144.  
  145. #ifdef THINK_C
  146.    PUSH_TRACE;
  147.    for (i=0; i<vertex_count; i++)
  148.       SRGP_pointCoord (vertices[i].x, FIXED(vertices[i].y));
  149.    POP_TRACE;
  150. #endif
  151.  
  152.    TURN_ON_RUBBER_ECHO_IF_ANY;
  153. }
  154.  
  155.  
  156. void
  157. SRGP_polyPointCoord (int vertex_count, int *x_coords, int *y_coords)
  158. {
  159.    register int i;
  160.  
  161.    DEBUG_AIDS{
  162.       SRGP_trace (SRGP_logStream, "SRGP_polyPointCoord  %d 0x%x,0x%x\n",
  163.           vertex_count, x_coords, y_coords);
  164.       srgp_check_system_state();
  165.       srgp_check_polymarker_list_size(vertex_count);
  166.       LeaveIfNonFatalErr();
  167.    }
  168.  
  169.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  170.    
  171. #ifdef X11
  172.    for (i=0; i < vertex_count; i++) {
  173.       Xformat_vertices[i].x = x_coords[i];
  174.       Xformat_vertices[i].y = FIXED(y_coords[i]);
  175.    } 
  176.    XDrawPoints
  177.       (srgpx__display,
  178.        srgp__curActiveCanvasSpec.drawable.xid,
  179.        srgp__curActiveCanvasSpec.gc_frame,
  180.        Xformat_vertices, vertex_count, CoordModeOrigin);
  181. #endif
  182.  
  183. #ifdef THINK_C
  184.    PUSH_TRACE;
  185.    for (i=0; i<vertex_count; i++)
  186.       SRGP_pointCoord (x_coords[i], FIXED(y_coords[i]));
  187.    POP_TRACE;
  188. #endif
  189.  
  190.    TURN_ON_RUBBER_ECHO_IF_ANY;
  191. }
  192.  
  193.  
  194.  
  195.  
  196. /** MARKERS
  197. **/
  198.  
  199. extern int srgp__marker_radius;  /* found in marker.c */
  200. static int linewidthtemp, saveLineWidth;
  201.  
  202. static void
  203. GetReadyToPaintMarkers (void)
  204. {
  205.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  206.    PUSH_TRACE;
  207.  
  208.    srgp__marker_radius = srgp__curActiveCanvasSpec.attributes.marker_size >> 1;
  209.  
  210. #ifdef THINK_C
  211.    SET_PORT_FOR_FRAME_GENRE();
  212. #endif
  213.  
  214.    saveLineWidth = srgp__curActiveCanvasSpec.attributes.line_width;
  215.    SRGP_setLineWidth
  216.       (((linewidthtemp=(srgp__marker_radius>>3))==0)?1:linewidthtemp);
  217. }
  218.  
  219.  
  220. static void
  221. FinishPaintingMarkers (void)
  222. {
  223.    SRGP_setLineWidth (saveLineWidth);
  224.  
  225.    POP_TRACE;
  226.    TURN_ON_RUBBER_ECHO_IF_ANY;
  227. }   
  228.  
  229.  
  230.    
  231. void 
  232. SRGP_markerCoord (int x, int y)
  233. {
  234.    DEBUG_AIDS{
  235.       SRGP_trace (SRGP_logStream, "SRGP_markerCoord: %d,%d\n", x,y);
  236.       srgp_check_system_state();
  237.       LeaveIfNonFatalErr();
  238.    }
  239.  
  240.    GetReadyToPaintMarkers();
  241.    switch (srgp__curActiveCanvasSpec.attributes.marker_style) {
  242.     case MARKER_CIRCLE: SRGP__drawCircleMarker (x,y); break;
  243.     case MARKER_SQUARE: SRGP__drawSquareMarker (x,y); break;
  244.     case MARKER_X: SRGP__drawXMarker (x,y); break;
  245.    }
  246.    FinishPaintingMarkers();
  247. }
  248.  
  249.    
  250. void 
  251. SRGP_marker (point pt)
  252. {
  253.    DEBUG_AIDS{
  254.       SRGP_trace (SRGP_logStream, "SRGP_marker: %d,%d\n", pt.x, pt.y);
  255.       srgp_check_system_state();
  256.       LeaveIfNonFatalErr();
  257.    }
  258.  
  259.    GetReadyToPaintMarkers();
  260.    switch (srgp__curActiveCanvasSpec.attributes.marker_style) {
  261.     case MARKER_CIRCLE: SRGP__drawCircleMarker (pt.x,pt.y); break;
  262.     case MARKER_SQUARE: SRGP__drawSquareMarker (pt.x,pt.y); break;
  263.     case MARKER_X: SRGP__drawXMarker (pt.x,pt.y); break;
  264.    }
  265.    FinishPaintingMarkers();
  266. }
  267.  
  268.    
  269. void 
  270. SRGP_polyMarker (int vertex_count, point *vertices)
  271. {
  272.    DEBUG_AIDS{
  273.       SRGP_trace (SRGP_logStream, "SRGP_polyMarker: %d  %lx\n", 
  274.           vertex_count, vertices);
  275.       srgp_check_polymarker_list_size(vertex_count);
  276.       srgp_check_system_state();
  277.       LeaveIfNonFatalErr();
  278.    }
  279.  
  280.    GetReadyToPaintMarkers();
  281.    while (vertex_count--) {
  282.       switch (srgp__curActiveCanvasSpec.attributes.marker_style) {
  283.        case MARKER_CIRCLE: 
  284.      SRGP__drawCircleMarker (vertices->x,vertices->y); break;
  285.        case MARKER_SQUARE: 
  286.      SRGP__drawSquareMarker (vertices->x,vertices->y); break;
  287.        case MARKER_X: 
  288.      SRGP__drawXMarker (vertices->x,vertices->y); break;
  289.       }
  290.       vertices++;
  291.    }
  292.    FinishPaintingMarkers();
  293. }
  294.  
  295.    
  296. void 
  297. SRGP_polyMarkerCoord (int vertex_count, int *xlist, int *ylist)
  298. {
  299.    DEBUG_AIDS{
  300.       SRGP_trace (SRGP_logStream, "SRGP_polyMarkerCoord: %d  %lx %lx\n", 
  301.           vertex_count, xlist, ylist);
  302.       srgp_check_polymarker_list_size(vertex_count);
  303.       srgp_check_system_state();
  304.       LeaveIfNonFatalErr();
  305.    }
  306.  
  307.    GetReadyToPaintMarkers();
  308.    while (vertex_count--) {
  309.       switch (srgp__curActiveCanvasSpec.attributes.marker_style) {
  310.        case MARKER_CIRCLE: SRGP__drawCircleMarker (*xlist, *ylist); break;
  311.        case MARKER_SQUARE: SRGP__drawSquareMarker (*xlist, *ylist); break;
  312.        case MARKER_X: SRGP__drawXMarker (*xlist, *ylist); break;
  313.       }
  314.       xlist++; ylist++;
  315.    }
  316.    FinishPaintingMarkers();
  317. }
  318.  
  319.    
  320.  
  321. /** LINES
  322. X11 handles dashes, etc. itself.
  323. Macintosh:  we must simulate all line styles other than continuous.
  324. **/
  325.  
  326.  
  327. #ifdef THINK_C
  328. typedef void (*voidfuncptr)();
  329. static int xpresent, ypresent;
  330. static boolean off;
  331.  
  332.  
  333. static void plotdash (int x, int y, int s)
  334. {
  335.    int j = s % 10;
  336.    off = (j < 5);
  337.    if ( ! off) {
  338.       MoveTo (x, y);
  339.       LineTo (x, y);
  340.    }
  341. }
  342.  
  343.  
  344. static void plotdot (int x, int y, int s)
  345. {
  346.    int j = s % 7;
  347.    off = (j < 5);
  348.    if ( ! off ) {
  349.       MoveTo (x, y);
  350.       LineTo (x, y);
  351.    }
  352. }
  353.  
  354.  
  355.  
  356. static void plotdotdash (int x, int y, int s)
  357. {
  358.    int j = s % 15;
  359.    off = (j < 4) || ((j > 5) && (j < 9));
  360.    if ( ! off) {
  361.       MoveTo (x, y);
  362.       LineTo (x, y);
  363.    }
  364. }
  365.  
  366.  
  367. static void LS_MOVETO (int x, int y)   /*Already Mac coordinates*/
  368. {
  369.    xpresent = x;
  370.    ypresent = y;
  371.    MoveTo (xpresent, ypresent);
  372. }
  373.  
  374.  
  375. static void LS_LINETO_difficult 
  376.    (int xnew, int ynew, 
  377.     voidfuncptr plot_with_line_style)
  378. {
  379.    register long_step, short_step, ax, di, bp, si, temp, x, y;
  380.    
  381.    long_step = 1;
  382.    short_step = 1;
  383.    bp = xnew - xpresent;
  384.    if (bp < 0)
  385.       {
  386.      long_step = -1;
  387.      bp = -bp;
  388.       };
  389.    ax = ynew - ypresent;
  390.    if (ax < 0)
  391.       {
  392.      short_step = -1;
  393.      ax = -ax;
  394.       };
  395.    x = xpresent;
  396.    y = ypresent;
  397.    if (ax <= bp)
  398.       {
  399.      di = bp>>1;
  400.      si = 0;
  401.      do {
  402.         plot_with_line_style (x, y, si);
  403.         x += long_step;
  404.         di += ax;
  405.         if (di >= bp)
  406.            {
  407.           di -= bp;
  408.           y += short_step;
  409.            }
  410.      }
  411.      while ((++si) <= bp);
  412.       }
  413.    else
  414.       {
  415.      temp = ax;
  416.      ax = bp;
  417.      bp = temp;
  418.      temp = short_step;
  419.      short_step = long_step;
  420.      long_step = temp;
  421.      di = (bp>>1);
  422.      si = 0;
  423.      do {
  424.         plot_with_line_style (x, y, si);
  425.         y += long_step;
  426.         di += ax;
  427.         if (di >= bp)
  428.            {
  429.           di -= bp;
  430.           x += short_step;
  431.            }
  432.      }
  433.      while ((++si) <= bp);
  434.       }
  435. };
  436.  
  437.  
  438. static void LS_LINETO (int xnew, int ynew) 
  439. {
  440.    if (srgp__curActiveCanvasSpec.attributes.line_style == CONTINUOUS)
  441.       LineTo (xnew, ynew);
  442.    else {
  443.       if (xnew == xpresent) 
  444.      PenSize (srgp__curActiveCanvasSpec.attributes.line_width, 1);
  445.       else if (ynew == ypresent) 
  446.      PenSize (1, srgp__curActiveCanvasSpec.attributes.line_width);
  447.       else if (abs(ynew - ypresent) < abs(xnew - xpresent))
  448.      PenSize (1, srgp__curActiveCanvasSpec.attributes.line_width);
  449.       else
  450.      PenSize (srgp__curActiveCanvasSpec.attributes.line_width, 1);
  451.       
  452.       switch (srgp__curActiveCanvasSpec.attributes.line_style) {
  453.        case DASHED: 
  454.      LS_LINETO_difficult (xnew, ynew, plotdash); break;
  455.        case DOTTED: 
  456.      LS_LINETO_difficult (xnew, ynew, plotdot); break;
  457.        case DOT_DASHED:
  458.      LS_LINETO_difficult (xnew, ynew, plotdotdash); break;
  459.       }
  460.    }
  461.    xpresent = xnew;
  462.    ypresent = ynew;
  463. }
  464.  
  465. #endif
  466.  
  467. void
  468. SRGP_lineCoord (int x1, int y1, int x2, int y2)
  469. {
  470.    DEBUG_AIDS{
  471.       SRGP_trace (SRGP_logStream, "SRGP_lineCoord: %d,%d --> %d,%d\n", x1,y1,x2,y2);
  472.       srgp_check_system_state();
  473.       LeaveIfNonFatalErr();
  474.    }
  475.  
  476.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  477. #ifdef X11
  478.    XDrawLine
  479.       (srgpx__display,
  480.        srgp__curActiveCanvasSpec.drawable.xid,
  481.        srgp__curActiveCanvasSpec.gc_frame,
  482.        x1, FIXED(y1), x2, FIXED(y2));
  483. #endif
  484. #ifdef THINK_C
  485.    SET_PORT_FOR_FRAME_GENRE();
  486.    LS_MOVETO (x1,FIXED(y1));
  487.    LS_LINETO (x2,FIXED(y2));
  488. #endif
  489.    TURN_ON_RUBBER_ECHO_IF_ANY;
  490. }
  491.  
  492. void
  493. SRGP_line (point pt1, point pt2)
  494. {
  495.    DEBUG_AIDS{
  496.       SRGP_trace (SRGP_logStream, "SRGP_line: %d,%d --> %d,%d\n", ExplodePt(pt1), ExplodePt(pt2));
  497.    }
  498.  
  499.    PUSH_TRACE;
  500.    SRGP_lineCoord (pt1.x, pt1.y,  pt2.x, pt2.y);
  501.    POP_TRACE;
  502. }
  503.  
  504.  
  505.  
  506. /** RECTANGLES
  507. **/
  508.  
  509. void
  510. SRGP_rectangleCoord (int left_x, int bottom_y, int right_x, int top_y)
  511. {
  512.    DEBUG_AIDS{
  513.       SRGP_trace (SRGP_logStream, "SRGP_rectangleCoord: (%d,%d)->(%d,%d)\n",
  514.           left_x, bottom_y, right_x, top_y);
  515.       srgp_check_system_state();
  516.       srgp_check_rectangle (left_x, bottom_y, right_x, top_y);
  517.       LeaveIfNonFatalErr();
  518.    }
  519.  
  520.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  521. #ifdef X11
  522.    XDrawRectangle
  523.       (srgpx__display,
  524.        srgp__curActiveCanvasSpec.drawable.xid,
  525.        srgp__curActiveCanvasSpec.gc_frame,
  526.        left_x, FIXED(top_y),
  527.        (right_x-left_x),
  528.        (top_y-bottom_y));
  529. #endif
  530. #ifdef THINK_C
  531.    SET_PORT_FOR_FRAME_GENRE();
  532.    r = FIXED_RECT(left_x, bottom_y, right_x, top_y);
  533.    if (srgp__curActiveCanvasSpec.attributes.line_style == CONTINUOUS)
  534.       FrameRect (&r);
  535.    else {
  536.       r.bottom -= srgp__curActiveCanvasSpec.attributes.line_width;
  537.       r.right -= srgp__curActiveCanvasSpec.attributes.line_width;
  538.       LS_MOVETO (r.left, r.bottom);
  539.       LS_LINETO (r.right, r.bottom);
  540.       LS_LINETO (r.right, r.top);
  541.       LS_LINETO (r.left, r.top);
  542.       LS_LINETO (r.left, r.bottom);
  543.    }
  544. #endif
  545.    TURN_ON_RUBBER_ECHO_IF_ANY;
  546. }
  547.  
  548. void
  549. SRGP_rectangle (rectangle rect)
  550. {
  551.    DEBUG_AIDS{
  552.       SRGP_trace (SRGP_logStream, "SRGP_rectangle: (%d,%d)->(%d,%d)\n", ExplodeRect(rect));
  553.    }
  554.  
  555.    PUSH_TRACE;
  556.    SRGP_rectangleCoord
  557.       (rect.bottom_left.x, rect.bottom_left.y,
  558.        rect.top_right.x, rect.top_right.y);
  559.    POP_TRACE;
  560. }
  561.  
  562. void
  563. SRGP_rectanglePt (point bottom_left, point top_right)
  564. {
  565.    DEBUG_AIDS{
  566.       SRGP_trace (SRGP_logStream, "SRGP_rectanglePt: (%d,%d)->(%d,%d)\n",
  567.           ExplodePt(bottom_left), ExplodePt(top_right));
  568.    }
  569.  
  570.    PUSH_TRACE;
  571.    SRGP_rectangleCoord
  572.       (bottom_left.x, bottom_left.y,
  573.        top_right.x, top_right.y);
  574.    POP_TRACE;
  575. }
  576.    
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583. /** FRAMED POLYGONS
  584. **/
  585.  
  586. void
  587. SRGP_polyLine (int vertex_count, point *vertices)
  588. {
  589.    register int i;
  590.  
  591.    DEBUG_AIDS{
  592.       SRGP_trace (SRGP_logStream, "SRGP_polyLine  %d 0x%x\n", vertex_count, vertices);
  593.       srgp_check_system_state();
  594.       srgp_check_polyline_list_size(vertex_count);
  595.       LeaveIfNonFatalErr();
  596.    }
  597.  
  598.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  599. #ifdef X11
  600.    for (i=0; i < vertex_count; i++) {
  601.       Xformat_vertices[i].x = vertices[i].x;
  602.       Xformat_vertices[i].y = FIXED(vertices[i].y);
  603.    } 
  604.    XDrawLines
  605.       (srgpx__display,
  606.        srgp__curActiveCanvasSpec.drawable.xid,
  607.        srgp__curActiveCanvasSpec.gc_frame,
  608.        Xformat_vertices, vertex_count, CoordModeOrigin);
  609. #endif
  610. #ifdef THINK_C
  611.    SET_PORT_FOR_FRAME_GENRE();
  612.    LS_MOVETO (vertices[0].x, FIXED(vertices[0].y));
  613.    for (i=1; i < vertex_count; i++)
  614.       LS_LINETO (vertices[i].x, FIXED(vertices[i].y));
  615. #endif
  616.    TURN_ON_RUBBER_ECHO_IF_ANY;
  617. }
  618.  
  619.  
  620. void
  621. SRGP_polyLineCoord (int vertex_count, int *x_coords, int *y_coords)
  622. {
  623.    register int i;
  624.  
  625.    DEBUG_AIDS{
  626.       SRGP_trace (SRGP_logStream, "SRGP_polyLineCoord  %d 0x%x,0x%x\n",
  627.           vertex_count, x_coords, y_coords);
  628.       srgp_check_system_state();
  629.       srgp_check_polyline_list_size(vertex_count);
  630.       LeaveIfNonFatalErr();
  631.    }
  632.  
  633.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  634. #ifdef X11
  635.    for (i=0; i < vertex_count; i++) {
  636.       Xformat_vertices[i].x = x_coords[i];
  637.       Xformat_vertices[i].y = FIXED(y_coords[i]);
  638.    } 
  639.    XDrawLines
  640.       (srgpx__display,
  641.        srgp__curActiveCanvasSpec.drawable.xid,
  642.        srgp__curActiveCanvasSpec.gc_frame,
  643.        Xformat_vertices, vertex_count, CoordModeOrigin);
  644. #endif
  645. #ifdef THINK_C
  646.    SET_PORT_FOR_FRAME_GENRE();
  647.    LS_MOVETO (x_coords[0], FIXED(y_coords[0]));
  648.    for (i=1; i < vertex_count; i++)
  649.       LS_LINETO (x_coords[i], FIXED(y_coords[i]));
  650. #endif
  651.    TURN_ON_RUBBER_ECHO_IF_ANY;
  652. }
  653.  
  654.  
  655. void
  656. SRGP_polygon (int vertex_count, point *vertices)
  657. {
  658.    DEBUG_AIDS{
  659.       SRGP_trace (SRGP_logStream, "SRGP_polygon  %d 0x%x\n", 
  660.           vertex_count, vertices);
  661.       srgp_check_system_state();
  662.       srgp_check_polygon_list_size(vertex_count);
  663.       LeaveIfNonFatalErr();
  664.    }
  665.  
  666.    PUSH_TRACE;
  667.    SRGP_polyLine (vertex_count, vertices);
  668.    /* draw the line between the first vertex and the last vertex */
  669.    SRGP_line (vertices[0], vertices[vertex_count-1]);
  670.    POP_TRACE;
  671. }
  672.  
  673.  
  674. void
  675. SRGP_polygonCoord (int vertex_count, int *x_coords, int *y_coords)
  676. {
  677.    DEBUG_AIDS{
  678.       SRGP_trace (SRGP_logStream, "SRGP_polygonCoord  %d 0x%x,0x%x\n",
  679.           vertex_count, x_coords, y_coords);
  680.       srgp_check_system_state();
  681.       srgp_check_polygon_list_size(vertex_count);
  682.       LeaveIfNonFatalErr();
  683.    }
  684.  
  685.    PUSH_TRACE;
  686.    SRGP_polyLineCoord (vertex_count, x_coords, y_coords);
  687.    /* draw the line between the first vertex and the last vertex */
  688.    SRGP_lineCoord
  689.       (x_coords[0], y_coords[0],
  690.        x_coords[vertex_count-1], y_coords[vertex_count-1]);
  691.    POP_TRACE;
  692. }
  693.  
  694.  
  695.  
  696. /** FILLED RECTANGLES AND POLYGONS
  697. **/
  698.  
  699. void
  700. SRGP_fillRectangleCoord (int left_x, int bottom_y, int right_x, int top_y)
  701. {
  702.    DEBUG_AIDS{
  703.       SRGP_trace (SRGP_logStream, "SRGP_fillRectangleCoord (%d,%d)->(%d,%d)\n",
  704.           left_x, bottom_y, right_x, top_y);
  705.       srgp_check_system_state();
  706.       srgp_check_rectangle(left_x, bottom_y, right_x, top_y);
  707.       LeaveIfNonFatalErr();
  708.    }
  709.  
  710.    
  711.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  712. #ifdef X11
  713.    XFillRectangle
  714.       (srgpx__display,
  715.        srgp__curActiveCanvasSpec.drawable.xid,
  716.        srgp__curActiveCanvasSpec.gc_fill,
  717.        left_x, FIXED(top_y),
  718.        (right_x-left_x+1), (top_y-bottom_y+1));
  719. #endif
  720. #ifdef THINK_C
  721.    SET_PORT_FOR_FILL_GENRE();
  722.    r = FIXED_RECT(left_x, bottom_y, right_x, top_y);
  723.    if (srgp__curActiveCanvasSpec.attributes.fill_style == PIXMAP_PATTERN)
  724.       FillCRect
  725.          (&r,
  726.           srgp__pixmapPatternTable
  727.              [srgp__curActiveCanvasSpec.attributes.fill_pixmap_pattern_id]);
  728.    else
  729.    PaintRect (&r);
  730. #endif
  731.    TURN_ON_RUBBER_ECHO_IF_ANY;  
  732. }
  733.  
  734. void
  735. SRGP_fillRectangle (rectangle rect)
  736. {
  737.    DEBUG_AIDS{
  738.       SRGP_trace (SRGP_logStream, "SRGP_fillRectangle (%d,%d)->(%d,%d)\n", 
  739.           ExplodeRect(rect));
  740.    }
  741.  
  742.    PUSH_TRACE;
  743.    SRGP_fillRectangleCoord
  744.       (rect.bottom_left.x, rect.bottom_left.y,
  745.        rect.top_right.x, rect.top_right.y);
  746.    POP_TRACE;
  747. }
  748.  
  749. void
  750. SRGP_fillRectanglePt (point bottom_left, point top_right)
  751. {
  752.    DEBUG_AIDS{
  753.       SRGP_trace (SRGP_logStream, "SRGP_fillRectanglePt (%d,%d)->(%d,%d)\n",
  754.           ExplodePt(bottom_left), ExplodePt(top_right));
  755.    }
  756.  
  757.    PUSH_TRACE;
  758.    SRGP_fillRectangleCoord
  759.       (bottom_left.x, bottom_left.y,
  760.        top_right.x, top_right.y);
  761.    POP_TRACE;
  762. }
  763.   
  764.  
  765. void
  766. SRGP_fillPolygon (int vertex_count, point *vertices)
  767. {
  768.    register int i;
  769. #ifdef THINK_C
  770.    PolyHandle p;
  771. #endif
  772.  
  773.    DEBUG_AIDS{
  774.       SRGP_trace (SRGP_logStream, "SRGP_fillPolygon:  %d  0x%x\n", 
  775.           vertex_count, vertices);
  776.       srgp_check_system_state();
  777.       srgp_check_polygon_list_size(vertex_count);
  778.       LeaveIfNonFatalErr();
  779.    }
  780.  
  781.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  782.  
  783. #ifdef X11
  784.    for (i=0; i < vertex_count; i++) {
  785.       Xformat_vertices[i].x = vertices[i].x;
  786.       Xformat_vertices[i].y = FIXED(vertices[i].y);
  787.    }
  788.    XFillPolygon
  789.       (srgpx__display,
  790.        srgp__curActiveCanvasSpec.drawable.xid,
  791.        srgp__curActiveCanvasSpec.gc_fill,
  792.        Xformat_vertices, vertex_count, Complex, CoordModeOrigin);
  793. #endif
  794.  
  795. #ifdef THINK_C
  796.    p = OpenPoly();
  797.    MoveTo (vertices[0].x, FIXED(vertices[0].y));
  798.    for (i=1; i < vertex_count; i++)
  799.       LineTo (vertices[i].x, FIXED(vertices[i].y));
  800.    ClosePoly ();
  801.    if (srgp__curActiveCanvasSpec.attributes.fill_style == PIXMAP_PATTERN)
  802.       FillCPoly 
  803.          (p,
  804.           srgp__pixmapPatternTable
  805.              [srgp__curActiveCanvasSpec.attributes.fill_pixmap_pattern_id]);
  806.    else {
  807.       SET_PORT_FOR_FILL_GENRE();
  808.       PaintPoly (p);
  809.    }
  810.    KillPoly (p);
  811. #endif
  812.  
  813.    TURN_ON_RUBBER_ECHO_IF_ANY;
  814. }
  815.  
  816.  
  817. void
  818. SRGP_fillPolygonCoord (int vertex_count, int *x_coords, int *y_coords)
  819. {
  820.    register int i;
  821. #ifdef THINK_C
  822.    PolyHandle p;
  823. #endif
  824.  
  825.    DEBUG_AIDS{
  826.       SRGP_trace (SRGP_logStream, "SRGP_fillPolygonCoord:  %d  0x%x,0x%x\n",
  827.           vertex_count, x_coords, y_coords);
  828.       srgp_check_system_state();
  829.       srgp_check_polygon_list_size(vertex_count);
  830.       LeaveIfNonFatalErr();
  831.    }
  832.  
  833.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  834.    
  835. #ifdef X11
  836.    for (i=0; i < vertex_count; i++) {
  837.       Xformat_vertices[i].x = x_coords[i];
  838.       Xformat_vertices[i].y = FIXED(y_coords[i]);
  839.    }
  840.    XFillPolygon
  841.       (srgpx__display,
  842.        srgp__curActiveCanvasSpec.drawable.xid,
  843.        srgp__curActiveCanvasSpec.gc_fill,
  844.        Xformat_vertices, vertex_count, Complex, CoordModeOrigin);
  845. #endif
  846.  
  847. #ifdef THINK_C
  848.    p = OpenPoly();
  849.    MoveTo (x_coords[0], FIXED(y_coords[0]));
  850.    for (i=1; i < vertex_count; i++)
  851.       LineTo (x_coords[i], FIXED(y_coords[i]));
  852.    ClosePoly ();
  853.    if (srgp__curActiveCanvasSpec.attributes.fill_style == PIXMAP_PATTERN)
  854.       FillCPoly 
  855.          (p,
  856.           srgp__pixmapPatternTable
  857.              [srgp__curActiveCanvasSpec.attributes.fill_pixmap_pattern_id]);
  858.    else {
  859.       SET_PORT_FOR_FILL_GENRE();
  860.       PaintPoly (p);
  861.    }
  862.    KillPoly (p);
  863. #endif
  864.    TURN_ON_RUBBER_ECHO_IF_ANY;
  865. }
  866.  
  867.  
  868.  
  869. /** ELLIPSES
  870. **/
  871.  
  872. #ifdef X11
  873. static int xangle1, xangle2;
  874.  
  875. ComputeXangles (double start, double end)
  876. {
  877.    if (start <= end) {
  878.       xangle1 = (int)(start*64);
  879.       xangle2 = (int)((end-start)*64);
  880.    }
  881.    else {
  882.       xangle1 = (int) (end*64);
  883.       xangle2 = (int) ((start-360.0-end)*64);
  884.    }
  885. }
  886. #endif
  887.    
  888. void
  889. SRGP_ellipseArc (rectangle bounding_rect, double start, double end)
  890. {
  891.  
  892.  
  893.    DEBUG_AIDS{
  894.       SRGP_trace (SRGP_logStream, "SRGP_ellipse:  (%d,%d)->(%d,%d)\n",
  895.           ExplodeRect(bounding_rect));
  896.       srgp_check_system_state();
  897.       srgp_check_rectangle
  898.      (bounding_rect.bottom_left.x, bounding_rect.bottom_left.y,
  899.       bounding_rect.top_right.x, bounding_rect.top_right.y);
  900.       LeaveIfNonFatalErr();
  901.    }
  902.  
  903.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  904. #ifdef X11
  905.    ComputeXangles (start, end);
  906.    XDrawArc
  907.       (srgpx__display,
  908.        srgp__curActiveCanvasSpec.drawable.xid,
  909.        srgp__curActiveCanvasSpec.gc_frame,
  910.        bounding_rect.bottom_left.x, FIXED(bounding_rect.top_right.y),
  911.        (bounding_rect.top_right.x - bounding_rect.bottom_left.x),
  912.        (bounding_rect.top_right.y - bounding_rect.bottom_left.y),
  913.        xangle1, xangle2);
  914. #endif
  915. #ifdef THINK_C
  916.    SetRect (&r, bounding_rect.bottom_left.x, FIXED(bounding_rect.top_right.y),
  917.            bounding_rect.top_right.x, FIXED(bounding_rect.bottom_left.y));
  918.    SET_PORT_FOR_FRAME_GENRE();
  919.    FrameArc (&r, (int)(90 - start), (int)(-(end+((start>end)?360:0) - start)));
  920. #endif
  921.    TURN_ON_RUBBER_ECHO_IF_ANY;
  922. }
  923.  
  924.  
  925. void
  926. SRGP_ellipse (rectangle bounding_rect)
  927. {
  928.    DEBUG_AIDS{
  929.       SRGP_trace (SRGP_logStream, "SRGP_ellipse:  (%d,%d)->(%d,%d)\n",
  930.           ExplodeRect(bounding_rect));
  931.       srgp_check_system_state();
  932.       srgp_check_rectangle
  933.      (bounding_rect.bottom_left.x, bounding_rect.bottom_left.y,
  934.       bounding_rect.top_right.x, bounding_rect.top_right.y);
  935.       LeaveIfNonFatalErr();
  936.    }
  937.  
  938.    PUSH_TRACE;
  939.    SRGP_ellipseArc (bounding_rect, 0.0, 360.0);
  940.    POP_TRACE;
  941. }
  942.  
  943.  
  944.  
  945.  
  946. void
  947. SRGP_fillEllipseArc (rectangle bounding_rect, double start, double end)
  948. {
  949.    DEBUG_AIDS{
  950.       SRGP_trace (SRGP_logStream, "SRGP_fillEllipseArc:  (%d,%d)->(%d,%d)\n",
  951.           ExplodeRect(bounding_rect));
  952.       srgp_check_system_state();
  953.       srgp_check_rectangle
  954.      (bounding_rect.bottom_left.x, bounding_rect.bottom_left.y,
  955.       bounding_rect.top_right.x, bounding_rect.top_right.y);
  956.       LeaveIfNonFatalErr();
  957.    }
  958.  
  959.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  960. #ifdef X11
  961.    ComputeXangles (start, end);
  962.    XFillArc
  963.       (srgpx__display,
  964.        srgp__curActiveCanvasSpec.drawable.xid,
  965.        srgp__curActiveCanvasSpec.gc_fill,
  966.        bounding_rect.bottom_left.x, FIXED(bounding_rect.top_right.y),
  967.        (bounding_rect.top_right.x - bounding_rect.bottom_left.x),
  968.        (bounding_rect.top_right.y - bounding_rect.bottom_left.y),
  969.        xangle1, xangle2);
  970. #endif
  971.  
  972. #ifdef THINK_C
  973.    SetRect (&r, bounding_rect.bottom_left.x, FIXED(bounding_rect.top_right.y),
  974.            bounding_rect.top_right.x, FIXED(bounding_rect.bottom_left.y));
  975.    if (srgp__curActiveCanvasSpec.attributes.fill_style == PIXMAP_PATTERN)
  976.       FillCArc (&r, (int)(90 - start), (int)(-(end+((start>end)?360:0) - start)),
  977.                 srgp__pixmapPatternTable
  978.                    [srgp__curActiveCanvasSpec.attributes.fill_pixmap_pattern_id]);
  979.    else {
  980.       SET_PORT_FOR_FILL_GENRE();
  981.       PaintArc (&r, (int)(90 - start), (int)(-(end+((start>end)?360:0) - start)));
  982.    }
  983. #endif
  984.    TURN_ON_RUBBER_ECHO_IF_ANY;
  985. }
  986.  
  987.  
  988.  
  989. void
  990. SRGP_fillEllipse (rectangle bounding_rect)
  991. {
  992.    DEBUG_AIDS{
  993.       SRGP_trace (SRGP_logStream, "SRGP_fillEllipse:  (%d,%d)->(%d,%d)\n",
  994.           ExplodeRect(bounding_rect));
  995.       srgp_check_system_state();
  996.       srgp_check_rectangle
  997.      (bounding_rect.bottom_left.x, bounding_rect.bottom_left.y,
  998.       bounding_rect.top_right.x, bounding_rect.top_right.y);
  999.       LeaveIfNonFatalErr();
  1000.    }
  1001.  
  1002.    PUSH_TRACE;
  1003.    SRGP_fillEllipseArc (bounding_rect, 0.0, 360.0);
  1004.    POP_TRACE;
  1005. }
  1006.  
  1007.  
  1008.  
  1009. /** TEXT
  1010. X11 implementation notes:
  1011.    Unfortunately, we don't keep a GC around just for text.
  1012.    Neither the frame nor the fill GC are necessarily correct for text;
  1013.    text is always drawn in SOLID style.
  1014.  
  1015.    Basically, if we find that the frame GC currently has a non-solid X-fill-style,
  1016.    we temporarily change the frame GC's X-fill-style to SOLID and then restore.
  1017.  
  1018.    This could be woefully inefficient if the application is indeed using
  1019.    a non-solid pen-style!
  1020. **/
  1021.  
  1022. void
  1023. SRGP_text (point origin, char *str)
  1024. {
  1025. #ifdef X11
  1026.    boolean restoration_needed = FALSE;
  1027. #endif
  1028.  
  1029.    DEBUG_AIDS{
  1030.       SRGP_trace (SRGP_logStream, "SRGP_text:  %d,%d  %s\n", 
  1031.           origin.x, origin.y, str);
  1032.       srgp_check_system_state();
  1033.       LeaveIfNonFatalErr();
  1034.    }
  1035.  
  1036.    TURN_OFF_RUBBER_ECHO_IF_ANY;
  1037.  
  1038. #ifdef X11
  1039.    if (srgp__curActiveCanvasSpec.attributes.pen_style != SOLID) {
  1040.       restoration_needed = TRUE;
  1041.       XSetFillStyle (srgpx__display,
  1042.              srgp__curActiveCanvasSpec.gc_frame, SOLID);
  1043.    }
  1044.  
  1045.    XDrawString
  1046.       (srgpx__display,
  1047.        srgp__curActiveCanvasSpec.drawable.xid,
  1048.        srgp__curActiveCanvasSpec.gc_frame,
  1049.        origin.x, FIXED(origin.y), str, strlen(str));
  1050.  
  1051.    if (restoration_needed)
  1052.       XSetFillStyle (srgpx__display,
  1053.              srgp__curActiveCanvasSpec.gc_frame,
  1054.              srgp__curActiveCanvasSpec.attributes.pen_style);
  1055. #endif
  1056.  
  1057. #ifdef THINK_C
  1058.    PenPat(black);
  1059.    CtoPstr(str);
  1060.    MoveTo (origin.x, FIXED(origin.y));
  1061.    DrawString (str);
  1062.    PtoCstr(str);
  1063. #endif
  1064.  
  1065.    TURN_ON_RUBBER_ECHO_IF_ANY;
  1066. }
  1067.